import {request} from "../../request/index.js"
Page({
  data:{
    minutes:'',
    payStatus:''
  },
  async onLoad(options){
    // 1、发请求 修改订单支付状态
    let that = this;
    let order_number=options.order_number;
    // 发请求 将订单支付状态改为付款
    const res=await request({url:"/payOk",method:"POST",data:{order_number}});
    if(res.data.result.affectedRows===1){
      // 付款成功 状态已经改为true
      that.setData({
        payStatus:'支付成功'
      })
    }else{
      that.setData({
        payStatus:'支付失败'
      })
    }
    //2、 3秒离开支付完成页面
    let minutes = 3;
    let timeOut = setInterval(()=>{
      minutes--;
      if(minutes>0){
        this.setData({
          minutes
        })
      }else{
        // 3s后跳转回购物车
        wx.switchTab({
          url: '/pages/cart/cart'
        })
        // 清除定时器
        clearInterval(timeOut)
      }
    },1000)
  }
})